package com.google.code.jmarias.client.components;

import com.google.code.jmarias.client.Entity;
import com.google.code.jmarias.client.Globals;
import com.google.code.jmarias.client.GameLocals;
import java.util.ArrayList;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

/**
 * Komponenta potvrzeni vybrane karty. 
 * Je vypsan informacni text a hrac muze pomoci klaves kartu potvrdit nebo zrusit.
 *
 * @author bart
 */
public class ConfirmPickedComponent extends AbstractRenderComponent {
    private ArrayList<Entity> cardsEntities;
    private Globals global;
    private GameLocals table;

    public ConfirmPickedComponent(int id, Globals global, GameLocals table, ArrayList<Entity> cardsEntities) throws SlickException {
        super(id);
        this.global = global;
        this.table = table;
        this.cardsEntities = cardsEntities;
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        Input input = gc.getInput();


        // Obsluha klavesnice - hrac muze ENTERem kartu potvrdit nebo pomoci ESC se vratit k vyberu
        if(input.isKeyPressed(Input.KEY_ENTER)) {            
            System.out.println("Potvrzeni vybrane karty (vybranych karet) - konec");
            owner.DelComponent(id);
        } else if(input.isKeyPressed(Input.KEY_ESCAPE)) {
            table.getCurrentPhase().refusePickedCards();
            table.setCurrentPhase(table.getCurrentPhase());
            owner.DelComponent(id);
        }

        for(int i=0; i < cardsEntities.size(); i++) {
            cardsEntities.get(i).update(gc, sb, delta);
        }
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
        global.printText("big", new Vector2f(100f, 150f), Color.white, "Odeslat? [Enter - Ano, ESC - Zpet]");

        for(int i=0; i < cardsEntities.size(); i++) {
            cardsEntities.get(i).render(gc, sb, gr);
        }
    }

}
